# -*- coding:utf-8 -*-
# @FileName  :dhcc_per_9_archive_revise.py
# @Time      :2020/12/24 16:39
# @Author    :Zhoujirong
# @Desc      : 授权信息补录
import datetime
import parameterized
from common.params_operator import Param
from common.log import Log
from biz.flow.per_archive_revise import PerArchiveReviseRequest
from biz.cases.base_case import BaseCase


class TestPerArchiveRevise(BaseCase):
    data_file_name = 'per_archive_revise.yaml'
    @classmethod
    def setUpClass(cls) -> None:
        cls.cookie = BaseCase().get_token()
        cls.archiveid = TestPerArchiveRevise().archive_create()
        cls.resultInfoId = TestPerArchiveRevise().get_page()

    def test_a_get_page(self):
        '''检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_customerName = self.file_data.get('search_EQ_customerName')
        search_EQ_certType = self.file_data.get('search_EQ_certType')
        search_EQ_certNo = self.file_data.get('search_EQ_certNo')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_queryType = self.file_data.get('search_EQ_queryType')
        search_EQ_queryFormat = '00'
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_status = self.file_data.get('search_EQ_status')
        tmp = datetime.date.today()
        search_GTE_LTE_queryTime_DATE_RANGE = '%s - %s'%(tmp,tmp)
        search_EQ_operator = self.file_data.get('search_EQ_operator')
        search_IN_operOrg = self.file_data.get('search_IN_operOrg')
        ret = PerArchiveReviseRequest.get_page(curPage,
            maxSize,
            search_EQ_customerName,
            search_EQ_certType,
            search_EQ_certNo,
            search_EQ_qryReason,
            search_EQ_queryType,
            search_EQ_queryFormat,
            search_EQ_source,
            search_EQ_status,
            search_GTE_LTE_queryTime_DATE_RANGE,
            search_EQ_operator,
            search_IN_operOrg,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)

    def get_page(self):
        '''检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_customerName = self.file_data.get('search_EQ_customerName')
        search_EQ_certType = self.file_data.get('search_EQ_certType')
        search_EQ_certNo = self.file_data.get('search_EQ_certNo')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_queryType = self.file_data.get('search_EQ_queryType')
        search_EQ_queryFormat = '00'
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_status = self.file_data.get('search_EQ_status')
        tmp = datetime.date.today()
        search_GTE_LTE_queryTime_DATE_RANGE = '%s - %s'%(tmp,tmp)
        search_EQ_operator = self.file_data.get('search_EQ_operator')
        search_IN_operOrg = self.file_data.get('search_IN_operOrg')
        ret = PerArchiveReviseRequest.get_page(curPage,
            maxSize,
            search_EQ_customerName,
            search_EQ_certType,
            search_EQ_certNo,
            search_EQ_qryReason,
            search_EQ_queryType,
            search_EQ_queryFormat,
            search_EQ_source,
            search_EQ_status,
            search_GTE_LTE_queryTime_DATE_RANGE,
            search_EQ_operator,
            search_IN_operOrg,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0].id #返回resultInfoId

    def test_b_page(self):
        '''授权档案管理补录新增页'''
        ret = PerArchiveReviseRequest.page(self.cookie)
        Log.info(ret)
        self.assertIn('授权信息补录新增',ret)

    def test_c_type(self):
        '''获取授权类型'''
        ret = PerArchiveReviseRequest.type(self.cookie)
        Log.info(ret)
        Type = self.file_data.get('Type')
        archiveType = str(self.file_data.get('archiveType'))
        Num = str(self.file_data.get('Num'))
        self.assertEqual(Type,ret.Type)
        self.assertEqual(archiveType,ret.archiveType)
        self.assertEqual(Num,ret.Num)

    def archive_create(self):
        '''补录授权文件'''
        archiveType = self.file_data.get('archiveType')
        Num = self.file_data.get('Num')
        clientName = self.file_data.get('search_EQ_customerName')
        cretType = self.file_data.get('search_EQ_certType')
        cretNo = self.file_data.get('search_EQ_certNo')
        startDate = datetime.date.today()
        expireDate = datetime.date.today()
        note = self.file_data.get('note')
        paperfileid = self.file_data.get('paperfileid')
        filedescribe = self.file_data.get('filedescribe')
        isRevise = self.file_data.get('isRevise')
        ret = PerArchiveReviseRequest.archive_create(archiveType, Num, clientName,
                                              cretType, cretNo, startDate,
                                              expireDate, note, paperfileid,
                                              filedescribe,isRevise, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        return ret.msg#返回archiveId

    @parameterized.parameterized.expand(Param.from_excel('authorize_data_pic.xls'))
    def test_d_upload(self, file, fileType, md5, needMd5, check, desc):
        self._testMethodDoc = desc  # 用例描述
        archiveId = self.archiveid
        resultInfoId = self.resultInfoId
        ret = PerArchiveReviseRequest.uploadfile(file, fileType, archiveId, resultInfoId, md5, needMd5, self.cookie)
        Log.info(ret)
        check = int(check)
        self.assertEqual(check, ret.code)

    def test_e_savepaper(self):
        '''保存授权档案'''
        paperfileid = self.file_data.get('paperfileid')
        filedescribe = self.file_data.get('filedescribe')
        archiveid = self.archiveid
        resultInfoId = self.resultInfoId
        ret = PerArchiveReviseRequest.savepaper(paperfileid,
                                                filedescribe,
                                                archiveid,
                                                resultInfoId,self.cookie)
        Log.info(ret)

    def test_f_lsit(self):
        '''授权信息补录列表'''
        ret =  PerArchiveReviseRequest.list(self.cookie)
        Log.info(ret)
        self.assertIn('授权信息补录列表',ret)















if __name__ == "__main__":
    pass